/* eslint-disable */
import config from './config'

export function get (url, data) {
  return request(url, 'GET', data)
}

export function post (url, data) {
  return request(url, 'POST', data)
}

export function request (url, method, data) {
  return new Promise((resolve, reject) => {
    wx.request({
      url:config.host + url,
      method:method,
      data:data,
      success: function(res) {
        if(res.data.code === 0) {
          resolve(res.data)
        }else{
          showModal('失败', res.data.data ? res.data.data.msg : res.data.error)
          reject(res.data)
        }
      }
    })
  })
}

export function showSuccess(text) {
  wx.showToast({
    title:text,
    icon:'success'
  })
}

export function showModal(title, content) {
  wx.showModal({
    title,
    content,
    showCancel: false
  })
}

export function showLoading() {
  // wx.showLoading({
  //   title: '加载中...',
  //   mark: true
  // })
  wx.showNavigationBarLoading()
}

export function hideLoading() {
  // wx.hideLoading()
  wx.hideNavigationBarLoading()
  wx.stopPullDownRefresh()
}